package com.tyson.context.controller;


import com.tyson.common.utils.R;
import com.tyson.context.entity.BlBlog;
import com.tyson.context.service.BlBlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 博客表 前端控制器
 * </p>
 *
 * @author 沈统顺
 * @since 2021-02-12
 */
@Api(tags= "博客管理")
@RestController
@RequestMapping("/context/bl-blog")
public class BlBlogController {
    @Autowired
    BlBlogService blBlogService;

    /**
     * 发布博客
     * @author 沈统顺
     */
    @ApiOperation(value = "保存博客")
    @PostMapping("saveBlog")
    public R saveBlog(@RequestBody BlBlog blBlog){
        boolean b = blBlogService.save(blBlog);
        if(b) return R.ok();
        else return R.error();
    }
    /**
     * 删除博客
     * @author 沈统顺
     */
    @ApiOperation(value = "删除博客")
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable("id") String id){
        blBlogService.removeById(id);
        return R.ok();
    }

    /**
     * 查询所有博客方法
     */
    @ApiOperation("查询所有博客方法")
    @GetMapping("list")
    public R list(){
        List<BlBlog> list = blBlogService.list();

        return R.ok().data("list",list);
    }
}

